package org.springblade.modules.ad.utils;

import lombok.Data;
import lombok.ToString;

/**
 * 结果返回类
 * @ClassName Result.java
 * @version 1.0.0
 * @author zhangyunjiao
 * @createTime 2021/8/27
 */

@Data
@ToString
public class Result {

	private String code;

	private String msg;

	private Object data;

	public static final String MSG 				    = "msg";

	public static final String DATA				    = "data";

	public static final String SUCCESS              = "success";

	public static final String OPER_FAILD			= "操作失败";

	public static final String OPER_SUCCESS			= "操作成功";

	public static final String BATCH_OPER_TIP		= "存在操作错误的数据，见详细列表！";


	public Result(){

	}

	public static Result of(){
		return new Result();
	}

	public Result(String code,String msg) {
		this.code = code;
		this.msg = msg;
	}

	public Result(String code, String msg, Object data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public Result(String code) {
		this.code = code;
	}

	/**
	 * 默认的成功
	 * @return
	 */
	public Result success(){
		return new Result (SUCCESS,OPER_SUCCESS);
	}

	/**
	 * 默认的失败
	 * @return
	 */
	public Result error(){
		return new Result (OPER_FAILD,OPER_FAILD);
	}


	/**
	 * 批量操作带失败详情的
	 * @return
	 */
	public Result error(Object detail){
		// 操作成功 提示语 失败详情
		return new Result (SUCCESS,BATCH_OPER_TIP,detail);
	}
	/**
	 * 失败提示语
	 * @return
	 */
	public Result error(String msg){
		return new Result (OPER_FAILD,msg);
	}

	/**
	 * 成功 + 返回的成功信息
	 * @param data
	 * @return
	 */
	public Result success(Object data){
		return new Result (SUCCESS,OPER_SUCCESS,data);
	}
}
